<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 16-4-8
  Time: 下午5:35
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<head>
    <jsp:include page="/include.jsp"/>
</head>
<body>
<object classid="clsid:0CFE290E-3B5F-4AC4-ABD9-00A088CC2110" id="TestLock" name="TestLock"
        codebase="http://localhost:8888/WebLock.ocx"
        width="110px" height="110px"></object>
<div id='write_card_dialog'>
    <div id="unspport" style="padding:50px;display:none;">
        <div>
            <h2>无法执行读卡操作</h2>

            <p>1. 命令已经被用户禁止！</p>

            <p>2. 未安装插件！点<a href="${pageContext.request.contextPath}/Lock.zip">这里</a>下载安装,安装方法见压缩包内的说明文件。</p>

            <p>2. 此功能必须使用ie浏览器，其他浏览器不支持！</p>
        </div>
    </div>
    <div id="read_card" style="text-align:center;vertical-align: middle;padding:80px;display:none;">
        <div>
            <img src="${pageContext.request.contextPath}/images/loading.gif">
            <br><br>

            <p>等待读卡中，请将智能卡放入读卡器内</p>

            <div style="padding: 5px;text-align: center;">
                <a href="javascript:;" class="easyui-linkbutton" onclick="ReadIDCard()"
                   data-options="iconCls:'icon-save'">开始读卡</a>
            </div>
        </div>
    </div>
    <div id="write_card" style="display:none;">
        <form id="write_card_form" name="write_card_form" method="post">
            <table class="listtable" style="width: 100%;">
                <tr class="row-even">
                    <td class="tr_left"><span class="required">*</span>智能卡号：</td>
                    <td class="tr_right">
                        <input type="text" name="CardNo" maxlength="200" class="easyui-validatebox" style="width: 300"
                               data-options="required:true,missingMessage:'请输入智能卡号'" readonly="readonly"/>
                    </td>
                </tr>
                <tr>
                    <td class="tr_left"><span class="required">*</span>门锁号：</td>
                    <td class="tr_right">
                        <textarea name="RoomNo" maxlength="200" class="easyui-validatebox" rows="4" style="width: 300"
                                  data-options="required:true,missingMessage:'请输入门锁号'" readonly="readonly"></textarea>
                    </td>
                </tr>
                <tr class="row-even">
                    <td class="tr_left"><span class="required">*</span>入住时间：</td>
                    <td class="tr_right">
                        <input type="text" name="InTime" value="${name}" maxlength="200" class="easyui-validatebox"
                               style="width: 300"
                               data-options="required:true,missingMessage:'请输入入住时间'" readonly="readonly"/>
                    </td>
                </tr>
                <tr>
                    <td class="tr_left"><span class="required">*</span>预离时间：</td>
                    <td class="tr_right">
                        <input type="text" name="OutTime" maxlength="200" class="easyui-validatebox" style="width: 300"
                               data-options="required:true,missingMessage:'请输入预离时间'" readonly="readonly"/>
                    </td>
                </tr>
            </table>
            <div style="padding: 5px;text-align: center;">
                <a href="javascript:;" class="easyui-linkbutton" onclick="MakeCard()"
                   data-options="iconCls:'icon-save'">确认无误，开始写卡</a>
            </div>
        </form>
    </div>
</div>


<script type="text/javascript">
    function execd(command) {
        window.oldOnError = window.onerror;
        window._command = command;
        window.onerror = function (err) {
            if (err.indexOf('utomation') != -1) {
                alert('命令已经被用户禁止！');
                return true;
            }
            else {
                //alert('命令可以使用！');
                return false;
            }
        };
        var wsh = new ActiveXObject('WScript.Shell');
        if (wsh)
            wsh.Run(command);
        window.onerror = window.oldOnError;
    }
    function HideActiveX() {
        if (!!window.ActiveXObject || "ActiveXObject" in window) {
            ClearIDCard();
            ClearForm();
            $('#read_card').show();
            return true;
        } else {
            $('#unspport').show();
            return;
        }
    }
    function ClearIDCard() {
        TestLock.RoomNo = "";
        TestLock.CardNo = "";
        TestLock.InTime = "";
        TestLock.OutTime = "";
        return true;
    }
    function ClearForm() {
        $('input[name="RoomNo"]').val("");
        $('input[name="CardNo"]').val("");
        $('input[name="InTime"]').val("");
        $('input[name="OutTime"]').val("");
        return true;
    }
    function FillForm() {
        //var pReadCard=TestLock.ReadCard;
        var pRoomNo = TestLock.RoomNo;
        var pCardNo = TestLock.CardNo;
        var pInTime = TestLock.InTime;
        var pOutTime = TestLock.OutTime;

        $('#read_card').hide();
        $('#write_card').show();
        return true;
    }
    function ConReadr() {
        if (typeof TestLock.ConReader == "undefined") {
            $.messager.show({
                title: '温馨提示',
                msg: "未检测到读卡器",
                timeout: 5000,
                showType: 'slide'
            });
            return false;
        }
        return true;
    }
    function ReadIDCard() {
        if (!ConReadr()) {
            return;
        }
        var cardsnr, roomno, intime, outtime;
        var pReadCard = TestLock.ReadCardEx();
        //输出的是一个字符串，中间用,隔开 格式：卡号,房号,入住时间,预离时间。
        var str = pReadCard.split(',');

        $('input[name="CardNo"]').val(str[0]);
//        $('input[name="RoomNo"]').val(str[1]);
//        $('input[name="InTime"]').val(str[2]);
//        $('input[name="OutTime"]').val(str[3]);

        FillForm();
        return true;
    }

    function loadRoomNos() {

    }

    function MakeCard() {
        if ($('#write_card_form').form("validate")) {
            var cardsnr = "";
            var roomno = $('input[name="RoomNo"]').val();
            var intime = $('input[name="RoomNo"]').val();
            var outtime = $('input[name="RoomNo"]').val();
            var pResult = TestLock.MakeCardEx(roomno, intime, outtime);
            $.messager.show({
                title: '温馨提示',
                msg: "写卡结果：" + pResult,
                timeout: 5000,
                showType: 'slide'
            });
        } else {
            return false;
        }
        return true;
    }
    function CancelCard() {
        var cardsnr = "";
        var pResult = TestLock.CancelCardEx();
        document.all['CardNo'].value = pResult;
        //document.all['CardNo'].value=cardsnr;
        return true;
    }

    //    $('#write_card_dialog').dialog({
    //        title: '写卡',
    //        width: 500,
    //        height: 300,
    //        closed: true,
    //        cache: false,
    //        modal: true
    //    });

    HideActiveX();
</script>

</body>
</html>